﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.DataAccessProvider;
using DTN.Core;

namespace Hanel.DTN.News
{
    public class tblEventManager : ItblEventManager
    {
        private static ItblEventManager itblEventManager = null;
        private tblEventManager()
        {
        }
        public static ItblEventManager CreateInstance()
        {
            if (itblEventManager == null)
            {
                itblEventManager = new tblEventManager();
            }
            return itblEventManager;
        }
        public DataTable SelecttblEventDynamic(string Where, string Order)
        {
            DataSet ds = new DataSet();
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@WhereCondition", SqlDbType.NVarChar,500),
																new SqlParameter("@OrderByExpression", SqlDbType.NVarChar,250),
															};
            parameters[0].Value = Where;
            parameters[1].Value = Order;
            try
            {
                ds = dataProvider.ExecuteDataSet("sp_Selecttbl_EventDynamic", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                return null;
            }
            return ds.Tables["Table"];
        }
        public DataTable SelecttblEventDynamic_top(string Top, string Where, string Order)
        {
            DataSet ds = new DataSet();
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            SqlParameter[] parameters = new SqlParameter[]{
                                                                new SqlParameter("@Top", SqlDbType.NVarChar,20),
																new SqlParameter("@WhereCondition", SqlDbType.NVarChar,500),
																new SqlParameter("@OrderByExpression", SqlDbType.NVarChar,250),
															};
            parameters[0].Value = Top;
            parameters[1].Value = Where;
            parameters[2].Value = Order;
            try
            {
                ds = dataProvider.ExecuteDataSet("sp_Selecttbl_EventDynamic_Top", CommandType.StoredProcedure, parameters);
            }
            catch (Exception ex)
            {
                return null;
            }
            return ds.Tables["Table"];
        }

    }
}
